home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Essentials / Developer Essentials Nov 90 / Apple II / Apple.II.partition / Tools / Technical.Notes / IIGS / TN.IIGS.053 < prev    next >
Encoding:
Text File  |  1990-09-21  |  14.6 KB  |  284 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6. Apple IIgs
  7. #53:    Desk Accessories and Tools
  8.  
  9. Revised by:    Dave Lyons    September 1990
  10. Written by:    Matt Deatherage & Jim Mensch    March 1989
  11.  
  12. This Technical Note discusses compatibility issues that can arise between desk 
  13. accessories and applications.  Where possible, it presents solutions.
  14. Changes since November 1989:  Added to the discussions of Close with reference 
  15. number zero and of when applications should start and shut down tools.  Noted 
  16. that StartUpTools is not intended to be called from an NDA.
  17. _____________________________________________________________________________
  18.  
  19. Desk accessories vary widely in complexity.  Classic Desk Accessories (CDAs) 
  20. range from simple status-reporting programs to complete system-level debugging 
  21. utilities, and similarly, New Desk Accessories (NDAs) range from static 
  22. windows with pictures to nearly full-fledged applications.
  23.  
  24. This Note presents some new guidelines aimed at helping developers of both 
  25. applications and desk accessories to get their products to work together now 
  26. and in the future.
  27.  
  28.  
  29. Tool Sets
  30.  
  31. The greatest conflict between applications and desk accessories, especially 
  32. NDAs, is the use of system tool sets.  The Apple IIgs Toolbox Reference, 
  33. Volume 1, defines which tools are available for use by NDAs.  The Desk Manager 
  34. requires starting the following tool sets before calling FixAppleMenu (which 
  35. installs the names of the NDAs in the Apple menu):
  36.  
  37.     Tool Locator (#1)
  38.     Memory Manager (#2)
  39.     Miscellaneous Tools (#3)
  40.     QuickDraw II (#4)
  41.     Event Manager (#6)
  42.     Window Manager (#14)
  43.     Menu Manager (#15)
  44.     Control Manager (#16)
  45.     LineEdit (#20)
  46.     Dialog Manager (#21)
  47.     Scrap Manager (#22)
  48.  
  49.  
  50. Since the Desk Manager requires starting these tools before calling 
  51. FixAppleMenu, NDAs may assume that these tools are all present and running, so 
  52. they do not need to check for their presence.  In addition to these 
  53. requirements by the Desk Manager, Apple strongly recommends that all 
  54. applications start the following tools:
  55.  
  56.     QuickDraw Auxiliary (#18)
  57.     Font Manager (#27)
  58.  
  59. These two additional tools are so widely used by desk accessories that they 
  60. should be present.  NDAs may not assume their presence, but it is reasonable 
  61. to write an NDA that checks for them, with the assumption that they usually 
  62. turn out to be available.
  63.  
  64.  
  65. The Golden NDA Guideline
  66.  
  67. Developers who wish to maintain maximum compatibility between their NDAs and 
  68. applications, both now and in the future, should consider every environment 
  69. change they make with the following Golden NDA Guideline firmly in mind:
  70.  
  71.     "I, an NDA, pledge not to alter the environment of the application 
  72.     under which I run, and I will behave in such a way that the 
  73.     application runs the same whether I am present or not."
  74.  
  75. Of course, this guideline does not include such necessary tasks as the normal 
  76. (and reasonable) allocation of memory.  An application must be prepared to 
  77. handle a memory allocation call by a desk accessory, operating system, or even 
  78. a tool at unexpected times.  The guideline does, however, mean that your desk 
  79. accessory cannot change the operating environment, including such things as 
  80. the presence of tools and operating system parameters.  The following sections 
  81. detail some of the most important ways to follow the Golden NDA Guideline.
  82.  
  83.  
  84. Desk Accessory Guidelines
  85.  
  86. Extra Tools
  87.  
  88.   o  If an NDA needs to use a tool which is not guaranteed to be available 
  89.      (e.g., Standard File), it should check to see if the tool is already 
  90.      running.  If it is not running, the NDA must use LoadOneTool to load it, 
  91.      then it must start the tool before using it.  When finished with the 
  92.      tool, the NDA must shut it down and unload it with UnloadOneTool.  (A 
  93.      tool is already running if its xxxStatus function returns TRUE and no 
  94.      error.)
  95.  
  96.   o  If an NDA needs to start up a tool and keep it started while letting the 
  97.      application continue to run, things quickly get complicated.  If your 
  98.      NDA starts a tool which the application is going to use but has not yet 
  99.      started (i.e., the Font Manager), and your NDA does not shut it down 
  100.      before the application regains control, the application (in this 
  101.      example) gets error $1B01 (Font Manager Already Started) when it makes 
  102.      an FMStartUp call.  Many applications stop gracelessly on getting a tool 
  103.      startup error.
  104.  
  105.      A previous version of this Note advised NDAs to start up and shut down 
  106.      tools when their windows were activated and deactivated.  This approach 
  107.      isn't strong enough to solve all the problems, since the application may 
  108.      decide to start up tools based on menu items (which can still be 
  109.      selected while an NDA window is in front).
  110.  
  111.      The only completely safe way to use a tool that isn't already running is 
  112.      to start it, use it, and shut it back down without ever returning 
  113.      control to the application while the tool set is started.
  114.  
  115.      Starting QuickDraw Auxiliary when the application has not started it can 
  116.      get you into a lot of trouble:  an application that correctly implements 
  117.      320/640 mode switching calls QDShutDown and QDStartUp.  QuickDraw 
  118.      Auxiliary depends heavily on QuickDraw, and restarting QuickDraw while 
  119.      QuickDraw Auxiliary is active easily toasts you.
  120.  
  121.   o  StartUpTools is designed to be called only by an application, not a desk 
  122.      accessory.  Unexpected things happen if your NDA calls StartUpTools (for 
  123.      example, you may get a second copy of the application's resource fork 
  124.      open in your NDA's private resource search path; this wastes RAM and can 
  125.      interfere with an application's attempt to write to its own resource 
  126.      fork).  For now, do not call StartUpTools from a DA.
  127.  
  128.   o  If your NDA allocates bank-zero work area space for tool sets, be sure 
  129.      to dispose of it at DeskShutDown time (when your DAInit entry is called 
  130.      for shutdown).  If you don't, the system dies with error $0201 when 
  131.      trying to launch a ProDOS 8 application, since GS/OS needs all of banks 
  132.      0 and 1 to start ProDOS 8.
  133.  
  134.   o  Sound tools are an exception to the rule of freely using a tool which is 
  135.      already started.  Refer to the section on System Parameters for more 
  136.      details on using sound tools.
  137.  
  138.   o  NDAs must not shut down tools which they have not started.
  139.  
  140.   o  CDAs are nearly always modal, but by using the HeartBeat interrupt queue 
  141.      or other mechanisms, they can get control when the user is no longer 
  142.      "in" the CDA.  The list of guaranteed tools for NDAs does not apply to 
  143.      CDAs, and CDAs must be prepared to deal with the ProDOS 8 environment as 
  144.      well as GS/OS.
  145.  
  146. System Parameters
  147.  
  148.   o  A desk accessory (CDA or NDA) must not change a system resource or 
  149.      parameter which cannot be restored to its original condition.  A 
  150.      trivial, but illustrative, example of this is the number of times a 
  151.      pull-down menu item blinks when you select it.  This number (three by 
  152.      default) may be changed with the SetMItemBlink call, but there is no 
  153.      corresponding GetMItemBlink call, so you cannot retrieve the current 
  154.      value.  Therefore, a desk accessory must not change this parameter, and 
  155.      the same rule applies to any other system parameter for which you cannot 
  156.      determine a current value.
  157.  
  158.   o  This idea extends to calling tool startup functions.  Even though a 
  159.      tool's startup function may not return an error when the tool is already 
  160.      active, the startup function could reset certain parameters upon which 
  161.      the application depends.  An example of this is TLStartUp for the Tool 
  162.      Locator.  A seemingly innocuous call, TLStartUp actually disconnects any 
  163.      user tool sets present, which, in this case, would most likely have been 
  164.      installed by the current application.  CDAs and NDAs must never call 
  165.      TLStartUp or TLShutDown.
  166.  
  167.      A desk accessory should generally not call a tool's startup function if 
  168.      the tool is already active.   Two exceptions are (1) the Memory 
  169.      Manager's MMStartUp call, which you can think of as a "GetMyID" call, 
  170.      and (2) ResourceStartUp, because the Resource Manager needs to be 
  171.      started up explicitly by each client (see Apple IIgs Technical Note #71, 
  172.      Desk Accessory Tips and Techniques).
  173.  
  174.   o  A desk accessory cannot use any of the sound tools if they are already 
  175.      started.  This is contrary to the rule for other tool sets, but it is 
  176.      required because there is no memory management of the sound RAM (or "DOC 
  177.      RAM").  If the Sound Tools (#8) are started, the application has 
  178.      exclusive control of the 64K DOC RAM used to play sounds.  Anything your 
  179.      desk accessory might put there could overwrite information the 
  180.      application needs.
  181.  
  182.      Saving and restoring DOC RAM around desk accessory usage is not 
  183.      sufficient.  Many of the sound functions are interrupt driven, altering 
  184.      the contents of DOC RAM only during sound interrupts, so your desk 
  185.      accessory might attempt to replace parts of DOC RAM which are being 
  186.      played.  Since there is no memory management of DOC RAM, desk 
  187.      accessories must avoid the sound functions of the IIgs if the 
  188.      application is already using them.
  189.  
  190.   o  A desk accessory must not install user tool sets, because there is no 
  191.      arbitration of user tool set numbers.  User tool sets are the sole 
  192.      property of the current application.
  193.  
  194.      A desk accessory should not call user tool sets even if it determines 
  195.      that the host application has installed a certain tool set, because that 
  196.      limits future system software options.  For example, consider a 
  197.      hypothetical multiple-application environment.  If DAs call user tool 
  198.      sets and the system automatically switches between separate collections 
  199.      of user tool sets, there would be no way for the system to know which 
  200.      set to switch in before giving control to a desk accessory.
  201.  
  202.  
  203. Application Guidelines
  204.  
  205. To coexist peacefully with desk accessories, particularly NDAs, applications 
  206. need to follow the guidelines listed in the Desk Manager chapter of the Apple 
  207. IIgs Toolbox Reference, Volume 1.  However, those applications which wish to 
  208. ensure maximum compatibility now and in the future also want to adhere to the 
  209. following:
  210.  
  211.   o  Be careful about when your application starts and shuts down tools.  A 
  212.      highly compatible approach is to start tools at the beginning of your 
  213.      application and leave them started.  For certain tools, like Standard 
  214.      File, it is reasonable to load and start the tool set each time it's 
  215.      needed (you may want to check whether it's already started, in case some 
  216.      impolite NDA started Standard File and left it started).
  217.  
  218.      Note that UnloadOneTool followed later by LoadOneTool does not 
  219.      necessarily cause disk access or ask the user to insert the boot disk.  
  220.      UnloadOneTool calls UserShutDown to put the tool set into "zombie" 
  221.      state, where it can be restarted from memory if none of its segments 
  222.      have been purged.  Unloading tools while they aren't in use is a Good 
  223.      Thing--if the user has plenty of RAM, there's no noticeable performance 
  224.      hit, but if RAM space is tight then doing extra disk access is 
  225.      preferable to actually running out of memory.
  226.  
  227.      For maximum compatibility, an application should not shut down any tools 
  228.      which were ever active when you called SystemTask or TaskMaster (until 
  229.      quitting time, of course, when you shut down everything, starting with 
  230.      the Desk Manager).  You can start more tools, but do not shut down those 
  231.      which are already active.  If you intend to start a tool and not keep it 
  232.      started, use it and then shut it down immediately, being sure not to 
  233.      call SystemTask or TaskMaster during that time.
  234.  
  235.      Future system software may provide arbitration of tool set use, but for 
  236.      now these guidelines provide a solution with which you can work.
  237.  
  238.   o  Don't just start the Scrap Manager--use it!  Many desk accessories 
  239.      support cutting and pasting to exchange text and pictures with your 
  240.      application, but they can do it only if you use the Scrap Manager.  If 
  241.      you have a need for your own private scrap internally, you should still 
  242.      also use the Scrap Manager to exchange text and pictures with other 
  243.      applications and DAs.
  244.  
  245.   o  Applications should not call CloseAllNDAs while shutting down.  Since 
  246.      DeskShutDown closes all open NDAs anyway, it's not necessary.  By not 
  247.      calling CloseAllNDAs, you allow the system or NDAs to tell the 
  248.      difference between just cleaning up and really wanting to close all the 
  249.      NDAs.
  250.  
  251.   o  Applications should never make a Close call with reference number zero 
  252.      at file level zero.  (If you need to use Close with reference number 
  253.      zero, use GetLevel and SetLevel to avoid closing files you did not open.  
  254.      Desk accessories should open files at level zero to ensure their files 
  255.      stay open when a DA-friendly application is using this scheme.)  It 
  256.      would be good if the system provided Desk Accessories with a way to open 
  257.      files and be certain that an application can never close them by 
  258.      accident, but for now this is a solution with which you can work.
  259.  
  260.   o  An application with some memory to spare can save NDAs time by providing 
  261.      them the additional tools which they are most likely to use.  If a desk 
  262.      accessory needs the List Manager and your application starts it, the 
  263.      desk accessory runs faster since it can avoid loading and starting the 
  264.      tool every time it gets control.
  265.  
  266.      The most common tools which desk accessories require besides those 
  267.      available in the standard Desk Manager set are QuickDraw Auxiliary 
  268.      (#18), the Print Manager (#19), Standard File (#23), the Font Manager 
  269.      (#27), and the List Manager (#28).  QuickDraw Auxiliary and the Font 
  270.      Manager are especially important--not only do they work well together, 
  271.      but they are also widely used.  In addition, FMStartUp can take a long 
  272.      time, and waiting for it every time you activate an NDA window can be 
  273.      really frustrating.  Many desk accessories also use the Print Manager, 
  274.      the List Manager, and Standard File, and if they are always available, 
  275.      desk accessories work more smoothly with your application.
  276.  
  277.  
  278. Further Reference:
  279. _____________________________________________________________________________
  280.   o  Apple IIgs Toolbox Reference
  281.   o  Programmer's Introduction to the Apple IIgs
  282.   o  Apple IIgs Technical Note #71, Desk Accessory Tips and Techniques
  283.  
  284.